home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7063 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  69 lines

  1. Newsgroups: comp.lang.c++
  2. Path: howland.reston.ans.net!psinntp!psinntp!psinntp!psinntp!bbnews1!trsvr!news
  3. From: Benjamin Romer <bmr1@trpo4.tr.unisys.com>
  4. Subject: Re: Is there a standard for * and & placement style?
  5. Sender: news@tr.unisys.com (cnews news id.)
  6. Message-ID: <312B5F0F.CFE@trpo4.tr.unisys.com>
  7. Date: Wed, 21 Feb 1996 18:06:07 GMT
  8. X-Nntp-Posting-Host: bmr1.tr.unisys.com
  9. Content-Transfer-Encoding: 7bit
  10. Content-Type: text/plain; charset=us-ascii
  11. References: <3128BD31.4AF8@wildfire.com> <marnoldDn27q9.Is0@netcom.com>
  12.         <4gckd5$bc7@clarknet.clark.net> <egpwb896e6.fsf@vipe.ii.uib.no>
  13. Mime-Version: 1.0
  14. X-Mailer: Mozilla 2.0 (WinNT; I)
  15. Organization: Unisys Corp.
  16.  
  17. Ketil Z Malde wrote:
  18. > Discussing
  19. >         int *ip;
  20. > vs.     int* ip;
  21. > one might also observe that "*ip" is, in fact, an int, just as much as
  22. > "ip" is an int*.  Just my two *.
  23. > -kzm
  24.  
  25. Actually there has been a great deal of argument about which is considered
  26. "correct", even though both work.
  27.  
  28. IMHO, the first method (int *ip) is safer for beginners, who might expect
  29.  
  30. int* a, b, c;
  31.  
  32. To define three pointers, while it in fact only defines one. This belief is
  33. further reinforced in a beginner's view by the use of * in typecasting,
  34. e.g. you must write (int*)ptrToAChar to get a pointer; if you write
  35. (int)*ptrToAChar you actually get an int. (I know you don't have to typecast
  36. char to int, it's only an example.) If you only define one variable per 
  37. statement, though, it looks and works just fine; personally, I'd write
  38.  
  39. int *a, *b, *c;
  40.  
  41. But that may just be stubbornness (and the fact that I've been using
  42. that format since college). Some would even go so far as to insist on
  43. using a typedef for pointers:
  44.  
  45. typedef int * ptrInt;
  46.  
  47. ptrInt ip, a, b, c;
  48.  
  49. This may be the safest way to do it but personally I think its a waste
  50. of typing. 
  51.  
  52. This is all merely opinion, though, and it really doesn't matter what you
  53. use as long as it compiles and your meaning is clear.
  54.  
  55. $0.02
  56.  
  57. Freely yours,
  58.  
  59. Ben Romer
  60. Software Engineer
  61. Unisys Corporation
  62.  
  63. #include <stddisclaim.h>
  64.